package com.arceus.leetcode.dytedance;

/**
 * 不要去考虑组合，转换成数字更好做
 * @author : iron
 * @version : 1.0.0
 * @date : 3:29 PM 2018/12/27
 */

public class T3 {
    public static void main(String[] args) {
        String s1 = "as";
        String s2 = "sdsaa";
        System.out.println(checkInclusion(s1, s2));
    }

    public static boolean checkInclusion(String s1, String s2) {
        int s1l, s2l;
        if ((s2l = s2.length()) < (s1l = s1.length()))
            return false;
        long s1v = 0;
        long s2v = 0;
        for (int i = 0; i < s1l; i++) {
            s1v += 1 << (s1.charAt(i) - 'a');
            s2v += 1 << (s2.charAt(i) - 'a');
        }
        int i = 0, j = s1l - 1;
        while (j < s2l) {
            if (s2v == s1v)
                return true;
            else {
                s2v -= 1 << (s2.charAt(i) - 'a');
                i++;
                j++;
                if (j < s2l)
                    s2v += 1 << (s2.charAt(j) - 'a');
            }
        }
        return false;
    }
}
